home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Softshoe / Lisa's Mac Parts / Pascal Strings / PString.h < prev    next >
Text File  |  2000-06-23  |  4KB  |  92 lines

  1. // PString.h
  2.  
  3. #ifndef PString_h
  4. #define PString_h
  5.  
  6. #ifndef Assert_h
  7. #include "Assert.h"
  8. #endif
  9. #ifndef Data_h
  10. #include "Data.h"
  11. #endif
  12. #ifndef ConstPString_h
  13. #include "ConstPString.h"
  14. #endif
  15.  
  16. class PString
  17.   {
  18.     private:
  19.         const Data space;
  20.  
  21.         const Data TextSpace()                                                { return space.Tail( 1 ); }
  22.         const Data SpaceTail( uint32 where )                            { return space.Tail( where + 1 ); }
  23.         const Data UnusedSpace()                                            { return space.Tail( Length() + 1u ); }
  24.         
  25.         enum{ maxStorageLength = maxuint8 + 1 };
  26.         
  27.     public:
  28.         PString( Data );
  29.         PString( Data, PString );
  30.         PString( Data, ConstPString );
  31.         PString( Data, const uint8 * );
  32.         PString( Data, ConstData text );
  33.  
  34.         uint8 Length() const                                                    { return space[0]; }
  35.         const URange32 Range() const                                                { return URange32( 0, Length() ); }
  36.         uint32 StorageLength() const                                        { return space.Length(); }
  37.         uint32 UnusedLength() const                                        { return space.Length() - space[0] - 1; }
  38.         
  39.         uint8& operator[]( uint32 i )                                        { Assert( i < Length() ); return space[i+1]; }
  40.         
  41.         const uint8& operator[]( uint32 i ) const                        { Assert( i < Length() ); return space[i+1]; }
  42.         
  43.         void Clear()                                                            { space[0] = 0; }
  44.         void Truncate( uint32 end );
  45.         void SetLength( uint32 );
  46.         
  47.         const Data Text()                                                        { return Data( &space[1], Length() ); }
  48.         const ConstData Text() const                                        { return ConstData( &space[1], Length() ); }
  49.         
  50.         const ConstData Head( uint32 size ) const                        { return Text().Head( size ); }
  51.         const ConstData Tail( uint32 position ) const                { return Text().Tail( position ); }
  52.         const ConstData Middle( URange32 range ) const                { return Text().Middle( range ); }
  53.  
  54.         const Data Head( uint32 size )                                    { return Text().Head( size ); }
  55.         const Data Tail( uint32 position )                                { return Text().Tail( position ); }
  56.         const Data Middle( URange32 range )                                { return Text().Middle( range ); }
  57.         
  58.         void operator=( ConstData );
  59.         void operator=( ConstPString string )                            { operator=( string.Text() ); }
  60.         void operator=( const PString& string )                        { operator=( string.Text() ); }
  61.         void operator=( const uint8 *string )                            { operator=( ConstPString( string ) ); }
  62.  
  63.         void operator+=( uint8 c );
  64.         void operator+=( ConstData );
  65.         void operator+=( ConstPString string )                            { operator+=( string.Text() ); }
  66.         void operator+=( const PString& string )                        { operator+=( string.Text() ); }
  67.         void operator+=( const uint8 *string )                            { operator+=( ConstPString( string ) ); }
  68.         
  69.         operator const uint8 *() const                                    { return space.Start(); }
  70.         operator ConstPString() const                                        { return ConstPString( space.Start() ); }
  71.         operator Data()                                                        { return Text(); }
  72.         operator ConstData() const                                            { return Text(); }
  73.         
  74.         uint8 *Raw()                                                            { return static_cast<uint8*>( space.Start() ); }
  75.         
  76.         void Remove( URange32 );
  77.         
  78.         void Insert( uint32 where, uint8 c );
  79.         void Insert( uint32 where, ConstData );
  80.         void Insert( uint32 where, ConstPString string )            { Insert( where, string.Text() ); }
  81.         void Insert( uint32 where, PString string )                    { Insert( where, string.Text() ); }
  82.         void Insert( uint32 where, const uint8 *string )            { Insert( where, ConstPString( string ) ); }
  83.         
  84.         void Replace( URange32 where, uint8 c );
  85.         void Replace( URange32 where, ConstData );
  86.         void Replace( URange32 where, ConstPString string )        { Replace( where, string.Text() ); }
  87.         void Replace( URange32 where, PString string )                { Replace( where, string.Text() ); }
  88.         void Replace( URange32 where, const uint8 *string )        { Replace( where, ConstPString( string ) ); }
  89.   };
  90.  
  91. #endif
  92.